<template>
	<view class="wrapper">
		<daya-footer-navbar menu_type="order" />

		<!-- <view @tap="mask1Cancel" :class="'mask ' + (mask1Hidden ? '' : 'maskactive')">
			<view class="maskbody">
				<view class="navbarlist">
					<view @tap="selectednavbar" :class="
              'toatal_head  ' + (selectedindex == index ? 'selsect' : 'default')
            " :data-index="index" :id="'a' + index" :style="'color:' + (selectedindex == index ? color : '')"
						v-for="(item, index) in navbar" :key="index">
						{{ item.name }}
					</view>
					<view @tap="onOverallTag" class="downpng1">
						<image :class="mask1Hidden ? 'sortimg' : 'sortimg1'"
							src="https://yunkeososyunchuc.bc8t.cn/ymq_canyino2o/static/down1.png"></image>
					</view>
				</view>
			</view>
		</view> -->
		<view class="sjinfonav" v-if="mask1Hidden">
			<scroll-view class="nav-two" :scrollIntoView="toView" :scrollX="true">
				<view @tap="selectednavbar" :class="
            'toatal_head  ' + (selectedindex == index ? 'selsect' : 'default')
          " :data-index="index" :id="'a' + index" 
					v-for="(item, index) in navbar" :key="index">
					{{ item.name }}

					<view class="toatal_text" style="'background-color:#1E9CFC '" v-if="selectedindex == index"></view>
				</view>
			</scroll-view>
			<!-- <view @tap="onOverallTag" class="downpng">
				<image src="https://yunkeososyunchuc.bc8t.cn/ymq_canyino2o/static/down1.png"></image>
			</view> -->
		</view>
		<view class="weui-cells weui-cells_after-title ddtz">
			<navigator class="weui-cell weui-cell_access" hoverClass="weui-cell_active" url="dmfdd">
				<view class="weui-cell__hd">
					<image mode="aspectFit" src="/static/ymq_canyino2o/dmfdd.png"></image>
				</view>
				<view class="weui-cell__bd">当面付订单</view>
				<!-- <view class="weui-cell__ft weui-cell__ft_in-access"></view> -->
			</navigator>
			<navigator class="weui-cell weui-cell_access" hoverClass="weui-cell_active" url="qgdd">
				<view class="weui-cell__hd">
					<image mode="aspectFit" src="/static/ymq_canyino2o/qgdd.png"></image>
				</view>
				<view class="weui-cell__bd">抢购订单</view>
				<!-- <view class="weui-cell__ft weui-cell__ft_in-access"></view> -->
			</navigator>


			<!--<navigator-->
			<!--  class="weui-cell weui-cell_access"-->
			<!--  hoverClass="weui-cell_active"-->
			<!--  url="/ymq_canyino2o/pages/sjzx/dndd/ptdd"-->
			<!--&gt;-->
			<!--  <view class="weui-cell__hd">-->
			<!--    <image-->
			<!--      mode="aspectFit"-->
			<!--      src="https://yunkeososyunchuc.bc8t.cn/ymq_canyino2o/static/personal/fenx.png"-->
			<!--    ></image>-->
			<!--  </view>-->
			<!--  <view class="weui-cell__bd">拼团订单</view>-->
			<!--  &lt;!&ndash; <view class="weui-cell__ft weui-cell__ft_in-access"></view> &ndash;&gt;-->
			<!--</navigator>-->


			<navigator class="weui-cell weui-cell_access" hoverClass="weui-cell_active" url="yydd">
				<view class="weui-cell__hd">
					<image mode="aspectFit" src="/static/ymq_canyino2o/yydd.png"></image>
				</view>
				<view class="weui-cell__bd">预约订单</view>
				<!-- <view class="weui-cell__ft weui-cell__ft_in-access"></view> -->
			</navigator>
			<navigator class="weui-cell weui-cell_access" hoverClass="weui-cell_active" url="pdlb">
				<view class="weui-cell__hd">
					<image mode="aspectFit" src="/static/ymq_canyino2o/pdqh.png"></image>
				</view>
				<view class="weui-cell__bd">排队取号</view>
				<!-- <view class="weui-cell__ft weui-cell__ft_in-access"></view> -->
			</navigator>
		</view>
		<view class="list">
			<view class="no-data-tip zwdd" v-if="order_list.length == 0 && mygd">
				<image mode="aspectFit" src="https://yunkeososyunchuc.bc8t.cn/ymq_canyino2o/static/list.png"></image>
				<view>暂无相关数据哦~</view>
			</view>
			<view class="table">
				<navigator class="tablecell flex-col flex-x-center flex-y-center" :style="
            'background-color: ' +
            (item.status == '1' ? color : '') +
            ';color:' +
            (item.status == '1' ? '#fff' : '')
          " :url="
            'dnddlb?table_id=' +
            item.id +
            '&name=' +
            item.name +
            '&status=' +
            item.status
          " v-for="(item, index) in order_list" :key="index">
					<view>{{ item.name }}</view>

					<view v-if="item.status == '1'">已开台</view>

					<view v-else>未开台</view>
				</navigator>
			</view>
			<view class="jzz" v-if="!mygd">
				<image class="Rotation" src="https://yunkeososyunchuc.bc8t.cn/ymq_canyino2o/static/jzz.png"></image>
				<view>加载中...</view>
			</view>
			<view class="jzwb" v-if="mygd">
				<view class="hx"></view>
				<view class="wz">加载完毕</view>
				<view class="hx"></view>
			</view>
		</view>
	</view>
</template>

<script>
	import cardlist from '@/ymq_canyino2o/dist/cardlist/index'
	import gettel from '@/ymq_canyino2o/dist/gettel/index'
	var dsq
	var app = getApp()
	var siteinfo = require('../../../../siteinfo.js');
	export default {
		components: {
			cardlist,
			gettel
		},
		data() {
			return {
				navbar: [{
					name: '全部',
					id: ''
				}],

				selectedindex: 0,
				mask1Hidden: true,
				img: 'http://img1.imgtn.bdimg.com/it/u=4078366710,4168441355&fm=200&gp=0.jpg',
				status: 1,
				pagenum: 1,
				order_list: [],
				storelist: [],
				mygd: false,
				jzgd: true,
				toView: '',


				color: ''
			}
		},
		onLoad: function(t) {
			var that = this
			var a = uni.getStorageSync('sjdsjid')
			var n = siteinfo.siteroot.replace('app/index.php', '')
			console.log(a, uni.getStorageSync('system'))
			uni.setNavigationBarTitle({
				title: uni.getStorageSync('system').dc_name || '店内'
			})
			app.globalData.setNavigationBarColor(this)
			app.globalData.sjdappPageOnLoad(this)
			app.globalData.util.request({
				url: 'entry/wxapp/TableType',
				cachetime: '0',
				data: {
					store_id: a
				},
				success: function(t) {
					var a = that.navbar.concat(t.data)
					console.log(t, a)
					that.setData({
						navbar: a
					})
				}
			})
			dsq = setInterval(function() {
				if (uni.getStorageSync('yybb')) {
					app.globalData.util.request({
						url: 'entry/wxapp/NewOrder',
						cachetime: '0',
						data: {
							store_id: a
						},
						success: function(t) {
							console.log(t)
							if (1 == t.data) {
								uni.playBackgroundAudio({
									dataUrl: n + 'addons/ymq_canyino2o/template/images/wm.wav',
									title: '语音播报'
								})
							}
							if (2 == t.data) {
								uni.playBackgroundAudio({
									dataUrl: n + 'addons/ymq_canyino2o/template/images/dn.wav',
									title: '语音播报'
								})
							}
						}
					})
				} else {
					clearInterval(dsq)
				}
			}, 10000)
			this.reLoad()
		},
		onReady: function() {},
		onShow: function() {},
		onHide: function() {},
		onUnload: function() {
			clearInterval(dsq)
		},
		onPullDownRefresh: function() {},
		onReachBottom: function() {
			console.log('上拉加载', this.pagenum)
			if (!this.mygd && this.jzgd) {
				this.setData({
					jzgd: false
				})
				this.reLoad()
			}
		},
		methods: {
			onOverallTag: function(t) {
				console.log(t)
				this.setData({
					mask1Hidden: false
				})
			},

			mask1Cancel: function() {
				this.setData({
					mask1Hidden: true
				})
			},

			selectednavbar: function(t) {
				console.log(t)
				this.setData({
					pagenum: 1,
					order_list: [],
					storelist: [],
					mygd: false,
					jzgd: true,
					selectedindex: t.currentTarget.dataset.index,
					toView: 'a' + (t.currentTarget.dataset.index - 1),
					status: Number(t.currentTarget.dataset.index) + 1
				})
				this.reLoad()
			},

			reLoad: function() {
				var t
				var that = this
				var a = this.status || 1
				var n = uni.getStorageSync('sjdsjid')
				var s = this.pagenum
				if (1 == a) {
					t = ''
				} else {
					t = that.navbar[a - 1].id
				}
				console.log(a, t, n, s)
				app.globalData.util.request({
					url: 'entry/wxapp/Table2',
					cachetime: '0',
					data: {
						type_id: t,
						store_id: n,
						page: s,
						pagesize: 20
					},
					success: function(t) {
						console.log('分页返回的列表数据', t.data)
						if (t.data.length < 20) {
							that.setData({
								mygd: true,
								jzgd: true
							})
						} else {
							that.setData({
								jzgd: true,
								pagenum: that.pagenum + 1
							})
						}
						var a = that.storelist
						a = (function(t) {
							for (var a = [], e = 0; e < t.length; e++) {
								if (-1 == a.indexOf(t[e])) {
									a.push(t[e])
								}
							}
							return a
						})((a = a.concat(t.data)))
						that.setData({
							order_list: a,
							storelist: a
						})
						console.log(a)
					}
				})
			}
		}
	}
</script>
<style scoped>
	@import './dndd.css';
</style>